﻿@model CustomerActionModel
@inject AdminAreaSettings adminAreaSettings
@{
    if (String.IsNullOrEmpty(Model.Id))
    {
        <div class="note note-info">
            @T("Admin.Customers.CustomerAction.SaveBeforeEdit")
        </div>
    }

    if (!String.IsNullOrEmpty(Model.Id))
    {
        <div class="panel panel-default">
            <div class="panel-body">
                <div id="conditions-grid"></div>
            </div>
            <div class="panel-footer">
                <button type="submit" id="btnAddNewCondition" name="btnAddNewCondition" onclick="javascript:setLocation('@(Url.Action("AddCondition", "CustomerAction", new { customerActionId = Model.Id }))'); return false;" class="k-button"><i class="fa fa-plus"></i>&nbsp;@T("Admin.Customers.CustomerAction.Conditions.AddNew")</button>
            </div>
        </div>
        <script>
        $(document).ready(function () {
            $("#conditions-grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            url: "@Html.Raw(Url.Action("Conditions", "CustomerAction", new { customerActionId = Model.Id }))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        },
                        destroy: {
                            url: "@Html.Raw(Url.Action("ConditionDelete", "CustomerAction", new { customerActionId = Model.Id }))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        }
                    },
                    schema: {
                        data: "Data",
                        total: "Total",
                        errors: "Errors",
                        model: {
                            id: "Id",
                        }
                    },
                    error: function (e) {
                        display_kendoui_grid_error(e);
                        // Cancel the changes
                        this.cancelChanges();
                    },
                    serverPaging: true,
                    serverFiltering: true,
                    serverSorting: true
                },
                pageable: {
                    refresh: true,
                    numeric: false,
                    previousNext: false,
                    info: false
                },
                editable: {
                    confirmation: true,
                    mode: "inline"
                },
                scrollable: false,
                columns: [
                {
                    field: "Name",
                    title: "@T("Admin.Customers.CustomerAction.Fields.Name")",
                    width: 300,
                    template: '<a class="k-link" href="@Url.Action("EditCondition", "CustomerAction")/?customerActionId=@(Model.Id)&cid=#=Id#">#=kendo.htmlEncode(Name)#</a>',
                },
                {
                    field: "Condition",
                    title: "@T("Admin.Customers.CustomerAction.Fields.ConditionType")",
                    width: 100,
                },
                {
                    command: { name: "destroy", text: "@T("Admin.Common.Delete")" },
                    title: "@T("Admin.Common.Delete")",
                    width: 100
                }]
            });
        });
        </script>

    }

}